package cn.itcast.mr.sort;

import org.apache.commons.lang3.StringUtils;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

/**
 * Author itcast
 * Date 2021/10/17 11:43
 * Desc TODO
 */
public class SortMapper extends Mapper<LongWritable, Text,SortPojo, NullWritable> {
    @Override
    protected void map(LongWritable key, Text value, Context context) throws IOException, InterruptedException {
        String line = value.toString();
        //实例化sortpojo
        SortPojo sortPojo = new SortPojo();
        if(StringUtils.isNotEmpty(line)){
            String[] arr = line.split("\t");
            sortPojo.setWord(arr[0]);
            sortPojo.setNum(Integer.parseInt(arr[1]));
            //context发送出去
            context.write(sortPojo, NullWritable.get());
        }
    }
}
